<template>
  <view class="container">
    <uni-forms ref="form" :modelValue="form" labelWidth="120px" labelPosition="top">
      <view class="hidden-title">提交验收</view>
      <view class="uni-container">
        <uni-forms ref="form" :modelValue="form" labelWidth="120px" labelPosition="top">
          <uni-table ref="table" border stripe emptyText="暂无更多数据" @selection-change="selectionChange">
            <uni-tr>
              <uni-th width="50" align="center">序号</uni-th>
              <uni-th width="150" align="center">验收事项</uni-th>
              <uni-th width="150" align="center">是否合格</uni-th>
            </uni-tr>
            <uni-tr v-for="(item, index) in form.itemList" :key="index">
              <uni-td>{{ index + 1 }}</uni-td>
              <uni-td>{{ item.acceptMatter }}</uni-td>
              <uni-td>
                <uni-forms-item :name="['itemList', index, 'acceptType']" class="acceptance" required>
                  <view slot="label">
                    <view class="flex align-center">
                      <view class="acceptance-list">
                        <view
                          class="acceptance-item"
                          v-for="(item, idx) in cureOptions"
                          :key="item.code"
                          :class="{ active: form.itemList[index].acceptType == item.dictValue }"
                          @click="form.itemList[index].acceptType = item.dictValue"
                        >
                          <image
                            class="icon-style"
                            v-show="form.itemList[index].acceptType != item.dictValue"
                            src="/static/images/work/dbd//selected_no.png"
                            mode="aspectFill"
                          ></image>
                          <image
                            class="icon-style"
                            v-show="form.itemList[index].acceptType == item.dictValue"
                            src="/static/images/work/dbd//selected_yes.png"
                            mode="aspectFill"
                          ></image>
                          <text class="content">{{ item.dictLabel }}</text>
                        </view>
                      </view>
                    </view>
                  </view>
                </uni-forms-item>
              </uni-td>
            </uni-tr>
          </uni-table>
          <view class="background-white bor-top">
            <uni-forms-item name="handoverType" label="交接验收意见" required>
              <uni-data-select v-model="form.handoverType" :localdata="range"></uni-data-select>
            </uni-forms-item>
            <uni-forms-item name="handoverInfo" label="意见说明" required>
              <textarea v-model="form.handoverInfo" class="text-area" placeholder="说明(限100字)" maxlength="100" />
            </uni-forms-item>
            <uni-forms-item name="examineCondition" label="检修后技术状况" required>
              <uni-easyinput
                type="textarea"
                v-model="form.examineCondition"
                placeholder="请输入检修后技术状况"
                maxlength="100"
              ></uni-easyinput>
            </uni-forms-item>
            <uni-forms-item name="remain" label="遗留问题" required>
              <uni-easyinput
                type="textarea"
                v-model="form.remain"
                placeholder="请输入遗留问题"
                maxlength="100"
              ></uni-easyinput>
            </uni-forms-item>
          </view>
        </uni-forms>
      </view>
    </uni-forms>
    <view class="submit-group">
      <button class="u-button" :ripple="true" @click="submit">提验</button>
    </view>
  </view>
</template>

<script>
import CuCellGroup from '@/components/cu-cell/cu-cell-group.vue'
import UserSelector from '@/components/user-selector/index.vue'
import ImageUpload from '@/components/image-upload/index.vue'
import { accept } from '@/api/repair/repair.js'
import { getDicts } from '@/api/system/dict.js'

export default {
  components: {
    CuCellGroup,
    UserSelector,
    ImageUpload
  },
  data() {
    return {
      cureOptions: [
        { dictLabel: '是', dictValue: 1 },
        { dictLabel: '否', dictValue: 2 }
      ],
      range: [
        { value: 'PASS', text: '合格' },
        { value: 'FAIL', text: '不合格' }
      ],
      id: '',
      procTaskId: '',
      form: {
        itemList: [],
        handoverType: '',
        handoverInfo: '',
        examineCondition: '',
        remain: ''
      }
    }
  },
  onLoad(option) {
    if (!option.data) return
    let data = JSON.parse(option.data)
    this.id = data.id
    this.procTaskId = data.procTaskId
  },
  mounted() {
    this.getCheckItem('dfm_device_examine_accept')
  },
  methods: {
    async getCheckItem(dictType) {
      const res = await getDicts(dictType)
      res.data.map((item) => {
        this.form.itemList.push({
          acceptMatter: item.dictLabel,
          acceptMatterKey: item.dictValue,
          acceptType: ''
        })
      })
    },
    submit() {
      this.$refs.form.validate().then((res) => {
        let data = {
          id: this.id,
          procTaskId: this.procTaskId,
          deviceExamineWorkflowEntity: {
            examineId: this.id,
            opinionType: 'PASS'
          },
          acceptInfo: this.form
        }
        accept(data).then((res) => {
          this.$modal.showToast('处理成功')
          uni.$emit('refresh')
          uni.navigateBack()
        })
      })
    }
  }
}
</script>

<style lang="scss">
.container {
  margin-bottom: 200rpx;

  .background-white {
    background-color: #fff;
    padding: 20rpx 30rpx;
    box-sizing: border-box;

    .uni-forms-item__label {
      color: #333;
      font-size: 30rpx;
    }

    .bor-btm {
      display: flex;
      border-bottom: 1px solid #d5d7e3;
    }

    .photo {
      display: flex;
      justify-content: space-between;

      image {
        width: 214rpx;
        height: 214rpx;
      }
    }

    .text {
      padding-bottom: 20rpx;
      padding-top: 4rpx;
      color: #333;

      text {
        color: #666;
      }
    }
  }
}

.hidden-title {
  background: #f5f5f5;
  padding: 20rpx;
  color: #999;
}

.bor-top {
  border-top: 20rpx solid #f5f5f5;
}

.blue {
  color: #88b4c4;
}

.icon-style {
  width: 52rpx;
  height: 42rpx;
  padding-right: 10rpx;
}
.input {
  display: inline-block;
  width: 100%;
  background-color: #f5f5f5;
  padding: 20rpx;
  font-size: 28rpx;
  border-radius: 10rpx;
  height: 60rpx;
}
.acceptance {
  margin-bottom: 10rpx;
}
.acceptance-list {
  display: flex;

  .acceptance-item {
    display: flex;
    align-items: center;
    margin-left: 20rpx;
    color: #333;

    .icon-style {
      width: 50rpx;
      height: 40rpx;
      margin-right: 10rpx;
    }

    .content {
      flex: 1;
    }
  }
}
</style>
